package com.example.springbootrabbitmq.lister;

import com.example.springbootrabbitmq.utils.AliCodeUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class ConsumerLister {

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @RabbitListener(queues = "java-queue")
    public void getMsg(Message message, String phone) throws Exception{
        System.out.println("接收到了需要发送验证码的手机号" + phone);
        AliCodeUtils aliCodeUtils = new AliCodeUtils();
        aliCodeUtils.sendLoginCode(phone, "123456");
        stringRedisTemplate.opsForValue().set(phone, "123456");
        stringRedisTemplate.expire(phone, 1, TimeUnit.MINUTES);
    }
}
